import { Manager } from "./manager.js";
class Role{
    constructor(w,h,x,y,imgUrl,boomUrl){
        this.w = w;
        this.h = h;
        this.x = x;
        this.y = y;
        this.imgUrl = imgUrl;
        this.boomUrl = boomUrl;
        this.isBoom = false;
        this.item = this.createRole();
    }
    createRole(){
        return $('<img>').appendTo('.gameStage').attr('src',this.imgUrl[0]).css({
            width:this.w,
            height:this.h,
            position:'absolute',
            left:this.x,
            top:this.y,
        })
    }
    boom(){
        if(this.boomUrl == undefined || this.boomUrl.length == 0){
            this.item.remove();
            return;
        }
        let index = 0;
        let _this = this;
        this.isBoom = true;
        let itimer = setInterval(() => {
            _this.item.attr('src',_this.boomUrl[index++]);
            if(index == _this.boomUrl.length){
                clearInterval(itimer)
                _this.item.remove()
                //从整体的敌人数组中删除掉enemy
                let index =  Manager.allEnemy.indexOf(_this); 
                if (index > -1) { 
                    Manager.allEnemy.splice(index, 1);
                }
            }
        }, 500/this.boomUrl.length);
    }
}

export {Role};